weather_df =
rnoaa::meteo_pull_monitors(
c("USW00094728", "USW00022534", "USS0023B17S"),
var = c("PRCP", "TMIN", "TMAX"),
date_min = "2021-01-01",
date_max = "2022-12-31") |>
mutate(
name = case_match(
id,
"USW00094728" ~ "CentralPark_NY",
"USW00022534" ~ "Molokai_HI",
"USS0023B17S" ~ "Waterhole_WA"),
tmin = tmin / 10,
tmax = tmax / 10) |>
select(name, id, everything())
## using cached file: /Users/david/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USW00094728.dly
## date created (size, mb): 2024-09-26 10:20:13.126901 (8.651)
## file min/max dates: 1869-01-01 / 2024-09-30
## using cached file: /Users/david/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USW00022534.dly
## date created (size, mb): 2024-09-26 10:20:18.991814 (3.932)
## file min/max dates: 1949-10-01 / 2024-09-30
## using cached file: /Users/david/Library/Caches/org.R-project.R/R/rnoaa/noaa_ghcnd/USS0023B17S.dly
## date created (size, mb): 2024-09-26 10:20:20.881069 (1.036)
## file min/max dates: 1999-09-01 / 2024-09-30
weather_df |>
ggplot(aes(x = tmin, y =tmax, color = name)) +
geom_point(alpha = 0.3) +
labs(
tittle = "Temperature scatterplot",
x = "Minimum Temperature(C)",
y = "Maximum Temperature(C)",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
)
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
Look at scale of axis
weather_df |>
ggplot(aes(x = tmin, y =tmax, color = name)) +
geom_point(alpha = 0.3) +
labs(
tittle = "Temperature scatterplot",
x = "Minimum Temperature(C)",
y = "Maximum Temperature(C)",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
) +
scale_x_continuous(
breaks = c(-15, 0, 20),
labels = c("-15", "0", "20")
) +
scale_y_continuous(
limits = c(0, 30),
transform = "sqrt",
position = "right"
)
## Warning in transformation$transform(x): NaNs produced
## Warning in scale_y_continuous(limits = c(0, 30), transform = "sqrt", position =
## "right"): sqrt transformation introduced infinite values.
## Warning: Removed 302 rows containing missing values or values outside the scale range
## (`geom_point()`).
Look at color
weather_df |>
ggplot(aes(x = tmin, y =tmax, color = name)) +
geom_point(alpha = 0.3) +
labs(
tittle = "Temperature scatterplot",
x = "Minimum Temperature(C)",
y = "Maximum Temperature(C)",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
) +
scale_x_continuous(
breaks = c(-15, 0, 20),
labels = c("-15", "0", "20")
) +
scale_y_continuous(
limits = c(0, 30)
) +
scale_color_hue(h = c(100, 400))
## Warning: Removed 302 rows containing missing values or values outside the scale range
## (`geom_point()`).
weather_df |>
ggplot(aes(x = tmin, y =tmax, color = name)) +
geom_point(alpha = 0.3) +
labs(
tittle = "Temperature scatterplot",
x = "Minimum Temperature(C)",
y = "Maximum Temperature(C)",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
) +
viridis::scale_color_viridis(
name = "Location", # alphabetic order
discrete = TRUE
)
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggp_scatterplot =
weather_df |>
ggplot(aes(x = tmin, y =tmax, color = name)) +
geom_point(alpha = 0.3) +
labs(
tittle = "Temperature scatterplot",
x = "Minimum Temperature(C)",
y = "Maximum Temperature(C)",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
) +
viridis::scale_color_viridis(
discrete = TRUE
)
ggp_scatterplot +
theme(legend.position = "bottom")
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggp_scatterplot +
theme_bw() +
theme(legend.position = "bottom")
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggp_scatterplot +
theme_classic() +
theme(legend.position = "bottom")
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
weather_df |>
ggplot(aes(x = date, y =tmax, color = name)) +
geom_point(aes(size = prcp), alpha = 0.3) +
geom_smooth(se = TRUE) +
labs(
tittle = "Temperature scatterplot",
x = "Date",
y = "Maximum Temperature(C)",
size = "Precipitation",
color = "location",
caption = "Weather data taken from rnoaa package for three stations."
) +
viridis::scale_color_viridis(
discrete = TRUE
) +
theme_minimal() +
theme(legend.position = "bottom")
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 19 rows containing missing values or values outside the scale range
## (`geom_point()`).
central_park_df =
weather_df |>
filter(name == "CentralPark_NY")
molokai_df =
weather_df |>
filter(name == "Molokai_HI")
molokai_df |>
ggplot(aes(x = date, y = tmax, color = name)) +
geom_point() +
geom_line(data = central_park_df)
## Warning: Removed 1 row containing missing values or values outside the scale range
## (`geom_point()`).
weather_df |>
ggplot(aes(x= tmax, fill = name)) +
geom_density() +
facet_grid(. ~ name)
## Warning: Removed 17 rows containing non-finite outside the scale range
## (`stat_density()`).
ggp_tmax_tmin =
weather_df |>
ggplot(aes(x = tmin, y = tmax, color = name)) +
geom_point(alpha = 0.3)
ggp_tmax_density =
weather_df |>
ggplot(aes(x = tmax, fill = name)) +
geom_density(alpha = 0.3)
ggp_tmax_date =
weather_df |>
ggplot(aes(x = date, y = tmax, color = name)) +
geom_point() +
geom_smooth(se = FALSE)
(ggp_tmax_tmin + ggp_tmax_density) / ggp_tmax_date
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
## Warning: Removed 17 rows containing non-finite outside the scale range
## (`stat_density()`).
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).